From 541a535f712092e37e0ac12e545cc56f7709d305 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 21 Sep 2014 10:22:46 -0700 Subject: [PATCH] Stop capturing output of all dependencies There are some competing concerns when it comes to the output of compiling dependencies: * Not capturing anything leads to getting drowned in unrelated output * Capturing requires coloration be compromised because of the way windows terminal colors are implemented. * Path dependencies are often developed in tandem with the rest of a package, and capturing their output is not always desired. To address these concerns, cargo previously captured output of dependent compilations and then re-printed it to the screen if an error occurred. This patch modifies the behavior to as follows: * No output is captured. This preserves any coloration rustc provides. * All dependencies are compiled with `-Awarnings`. This should suppress any extraneous output from the compiler and it is considered a bug otherwise if the compiler prints a warnings when `-Awarnings` is specified. * All *path* dependencies (`path="..."`, overrides, etc) are *not* compiled with `-Awarnings`. The reason for this is that you are always in control of these packages and probably want to see warnings anyway. Closes #490 Closes #496 --- .travis.install.deps.sh | 2 ++ src/cargo/ops/cargo_rustc/mod.rs | 19 +++++----------- tests/test_cargo_compile.rs | 6 ++++- tests/test_cargo_compile_git_deps.rs | 33 ++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/.travis.install.deps.sh b/.travis.install.deps.sh index 94d3db28c..4a082e923 100755 --- a/.travis.install.deps.sh +++ b/.travis.install.deps.sh @@ -25,6 +25,7 @@ host=static-rust-lang-org.s3.amazonaws.com # just install the right ones? This should enable cross compilation in the # future anyway. if [ -z "${windows}" ]; then + rm -rf rustc *.tar.gz curl -O https://$host/dist/rust-nightly-i686-$target.tar.gz curl -O https://$host/dist/rust-nightly-x86_64-$target.tar.gz tar xfz rust-nightly-i686-$target.tar.gz @@ -49,6 +50,7 @@ if [ -z "${windows}" ]; then rm -f rust-nightly-i686-$target.tar.gz rm -f rust-nightly-x86_64-$target.tar.gz else + rm -rf rustc *.exe if [ "${BITS}" = "64" ]; then triple=x86_64-w64-mingw32 else diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index f79329639..ea59bab11 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -237,26 +237,19 @@ fn rustc(package: &Package, target: &Target, log!(5, "root={}; target={}; crate_types={}; verbose={}; req={}", root.display(), target, crate_types, cx.primary, req); - let primary = cx.primary; let rustcs = try!(prepare_rustc(package, target, crate_types, cx, req)); Ok(rustcs.into_iter().map(|(rustc, kind)| { let name = package.get_name().to_string(); let desc = rustc.to_string(); + let is_path_source = package.get_package_id().get_source_id().is_path(); + let show_warnings = cx.primary || is_path_source; + let rustc = if show_warnings {rustc} else {rustc.arg("-Awarnings")}; (proc() { - if primary { - log!(5, "executing primary"); - try!(rustc.exec().chain_error(|| { - human(format!("Could not compile `{}`.", name)) - })) - } else { - log!(5, "executing deps"); - try!(rustc.exec_with_output().and(Ok(())).map_err(|err| { - caused_human(format!("Could not compile `{}`.\n{}", - name, err.output().unwrap()), err) - })) - } + try!(rustc.exec().chain_error(|| { + human(format!("Could not compile `{}`.", name)) + })); Ok(()) }, kind, desc) }).collect()) diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index dc4c39983..3d3c569d4 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -213,7 +213,11 @@ test!(cargo_compile_with_warnings_in_a_dep_package { {} foo v0.5.0 ({})\n", COMPILING, p.url(), COMPILING, p.url())) - .with_stderr("")); + .with_stderr("\ +[..]warning: code is never used: `dead`[..] +[..]fn dead() {} + +")); assert_that(&p.bin("foo"), existing_file()); diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 181de8f9b..284ad2622 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -1273,3 +1273,36 @@ test!(fetch_downloads { assert_that(p.process(cargo_dir().join("cargo")).arg("fetch"), execs().with_status(0).with_stdout("")); }) + +test!(warnings_in_git_dep { + let bar = git_repo("bar", |project| { + project.file("Cargo.toml", r#" + [package] + name = "bar" + version = "0.5.0" + authors = ["wycats@example.com"] + "#) + .file("src/lib.rs", "fn unused() {}") + }).assert(); + + let p = project("foo") + .file("Cargo.toml", format!(r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + [dependencies.bar] + git = '{}' + "#, bar.url()).as_slice()) + .file("src/main.rs", "fn main() {}"); + + assert_that(p.cargo_process("build"), + execs() + .with_stdout(format!("{} git repository `{}`\n\ + {} bar v0.5.0 ({}#[..])\n\ + {} foo v0.5.0 ({})\n", + UPDATING, bar.url(), + COMPILING, bar.url(), + COMPILING, p.url())) + .with_stderr("")); +}) -- 2.30.2